<?php
/**
 * Framework_OpenID
 *
 * @author      Ian Szewczyk <roamzero@gmail.com>
 * @copyright   (c) 2007 Ian Szewczyk. All rights reserved.
 * @license     http://www.opensource.org/licenses/bsd-license.php
 * @package Framework
 * @filesource
 */

define('Auth_OpenID_RAND_SOURCE', null);
require_once 'Auth/OpenID.php';


/**
 * Framework_OpenID
 *
 * A basic wrapper for the PHP openID library
 *
 * @author Ian Szewczyk <roamzero@gmail.com>
 * @link http://pear.php.net/manual/en/package.html.pager.php
 * @package Framework
 * 
 */
abstract class Framework_OpenID
{
    
	/**
     * factoryConsumer
     *
     * @access 		public
     * @param 		string 		$store
     * @return		mixed 		Instance of Framework_OpenID_Consumer on success, PEAR_Error
     * @static
     */
	static public function factoryConsumer($store = 'db')
    {
        $file = 'Framework/OpenID/Consumer.php';
        if (!include_once($file)) {
            return PEAR::raiseError('Could not load consumer file: '.$file);
        }

        $class = 'Framework_OpenID_Consumer';
        if (!class_exists($class)) {
            return PEAR::raiseError('Could not find consumer class: '.$class); 
        }

        try {
            $instance = new $class($store);
            if (!$instance instanceof Framework_OpenID_Consumer) {
                return PEAR::raiseError('Invalid Class');
            }
        } catch (Framework_Exception $error) {
            return PEAR::raiseError($error->getMessage());
        }

        return $instance;
         
   
    }
    
    /**
     * factoryServer
     *
     * @access 		public
     * @param 		string 		$store
     * @return		mixed 		Instance of Framework_OpenID_Factory on success, PEAR_Error
     * @static
     */
    static public function factoryServer($store = 'db')
    {
    	
    	$file = 'Framework/OpenID/Server.php';
        if (!include_once($file)) {
            return PEAR::raiseError('Could not load server file: '.$file);
        }

        $class = 'Framework_OpenID_Server';
        if (!class_exists($class)) {
            return PEAR::raiseError('Could not find server class: '.$class); 
        }

        try {
            $instance = new $class($store);
            if (!$instance instanceof Framework_OpenID_Server) {
                return PEAR::raiseError('Invalid Class');
            }
        } catch (Framework_Exception $error) {
            return PEAR::raiseError($error->getMessage());
        }

        return $instance;
    	
   
    }
    
    /**
     * getIdentity
     *
     * @access 		public
     * @return 		mixed 		HTTP identity path, null
     * @static
     */
    static public function getIdentity()
    {
    	$user = Framework_User::singleton();
    	
    	if ($user->getUserStatus() == OWNER_USER_STATUS) {
    		return Framework::$request->getBaseHTTPPath().'/'.$user->userName;
    	} else {
    		return null;
    	}
    }
}

?>
